// temp pt00
#include <p18cxxx.h>
//#include "./USB/usb_function_cdc.h"
//#include "GenericTypeDefs.h"
//#include "Compiler.h"
//#include "usb_config.h"
//#include "USB/usb_device.h"
//#include "USB/usb.h"
//#include "HardwareProfile.h"
#include <delays.h>
#include <adc.h>
#pragma config FOSC=HSPLL_HS, PLLDIV=5, CPUDIV=OSC1_PLL2
#pragma config USBDIV=2, PWRT=ON, FCMEN=ON, IESO=ON
#pragma config BOR=ON, BORV=0, WDT=OFF, LVP=OFF, VREGEN=ON
#pragma config MCLRE=ON, PBADEN=OFF, WDTPS=1024
#pragma config LPT1OSC=OFF, CCP2MX=OFF, DEBUG=OFF
#pragma config CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF
#pragma config CPD=OFF, WRT0=OFF, WRT1=OFF, WRT2=OFF, WRT3=OFF
#pragma config WRTB=OFF, WRTC=OFF, WRTD=OFF, EBTR0=OFF
#pragma config EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF
#define lcd_DB LATB
#define lcd_E LATBbits.LATB1
#define lcd_RS LATBbits.LATB0
#define Delay_50uS Delay100TCYx(6)
#define Delay_100uS Delay100TCYx(12)
#define Delay_1mS Delay1KTCYx(12)
#define Delay_2mS Delay1KTCYx(24)
#define Delay_5mS Delay10KTCYx(6)
#define Delay_10mS Delay10KTCYx(12)
#define Delay_20mS Delay10KTCYx(24)
#define Delay_100mS Delay10KTCYx(120)
unsigned int T, TT, setT;
unsigned char n;
unsigned char a0, a1, a2, a3, a4, a5, a6, a7;
char buf[4];
char buff[4];
char temp[] = "Temp";
char setTemp[] = "setT";
void YourHighPriorityISRCode();
void YourLowPriorityISRCode();
void lcd_w4(char asci);
void lcd_c4(char cmd);
void lcd_clr(void);
void lcd_puts(char *s);
void lcd_locate(char y,char x);
void lcd_putT(unsigned int T);
void lcd_putsetT(unsigned int setT);
void lcd_init(void);
#pragma code REMAPPED_HIGH_INTERRUPT_VECTOR = 0x08
void Remapped_High_ISR (void){
_asm goto YourHighPriorityISRCode _endasm
}
#pragma code REMAPPED_LOW_INTERRUPT_VECTOR = 0x18
void Remapped_Low_ISR (void){
_asm goto YourLowPriorityISRCode _endasm
}
#pragma code
#pragma interrupt YourHighPriorityISRCode
void YourHighPriorityISRCode(){
//USBDeviceTasks();
}
#pragma interruptlow YourLowPriorityISRCode
void YourLowPriorityISRCode(){
}
#pragma code
void lcd_w4(char c){
lcd_DB = (c & 0xF0) | (lcd_DB & 0x0F);
lcd_E = 1;
Delay10TCYx(20);
lcd_E = 0;
}
void lcd_c4(char c){
lcd_RS = 0;
lcd_w4(c);
lcd_w4(c<<4);
if(c & 0xFC)
Delay_50uS;
else
Delay_2mS;
}
void lcd_clr(void){
lcd_c4(0x01);
}
void lcd_locate(char y, char x){
unsigned char p;
switch(y & 0x03){
case 0: p=0x80; break;
case 1: p=0xC0; break;
case 2: p=0x94; break;
case 3: p=0xD4; break;
}
lcd_c4(p += x);
}
void lcd_putchr(char c){
lcd_RS = 1;
lcd_w4(c);
lcd_w4(c<<4);
Delay_50uS;
}
void lcd_puts(char *s){
while(*s)
lcd_putchr(*s++);
}
void lcd_putT(
unsigned int T){
unsigned char i;
for(i=0; i<4; i++) buf[i] = ' ';
i = 3;
do{
buf[i] = (T % 10) + '0';
T = T / 10;
i--;
} while(T > 0);
for(i=0; i<4; i++) lcd_putchr(buf[i]);
}
void lcd_putsetT(
unsigned int setT){
unsigned char i;
for(i=0; i<4; i++) buff[i] = ' ';
i = 3;
do{
buff[i] = (setT % 10) + '0';
setT = setT / 10;
i--;
} while(setT > 0);
for(i=0; i<4; i++) lcd_putchr(buff[i]);
}
void lcd_putui(
unsigned int ui, unsigned char d){
unsigned char i;
unsigned char buf[4];
for(i = 0; i < 4; i++)
buf[i] = ' ';
i = 3;
do {
buf[i] = (ui % 10) + '0';
ui = ui / 10;
i--;
} while(ui > 0);
for(i = (4 - d); i < 4; i++)
lcd_putchr(buf[i]);
}
void lcd_init(void){
Delay_20mS;
lcd_RS = 0;
lcd_w4(0x30);Delay_5mS;
lcd_w4(0x30);Delay_1mS;
lcd_w4(0x30);Delay_1mS;
lcd_w4(0x20);Delay_1mS;
lcd_c4(0x2E);
lcd_c4(0x08);
lcd_c4(0x0C);
lcd_c4(0x06);
lcd_c4(0x01);
}
void main(void){
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTE = 0x00;
TRISA = 0b11111111;
TRISB = 0b00000000;
TRISC = 0b00000111;
ADCON0 = 0b00000001; // ADCON ON
ADCON1 = 0b00001110; // AN0 のみアナログ, Vss-Vdd
ADCON2 = 0b10100110; // Right,12Tad,1/64
PORTBbits.RB2 = 0;
lcd_init();
while(1){
a0 = 0; a1 = 0; a2 = 0; a3 = 0;
a4 = 0; a5 = 0; a6 = 0; a7 = 0;
if(PORTAbits.RA1==0) a7 = 1;
if(PORTAbits.RA2==0) a6 = 1;
if(PORTAbits.RA3==0) a5 = 1;
if(PORTAbits.RA4==0) a4 = 1;
if(PORTAbits.RA5==0) a3 = 1;
if(PORTCbits.RC0==0) a2 = 1;
if(PORTCbits.RC1==0) a1 = 1;
if(PORTCbits.RC2==0) a0 = 1;
setT = a7*128 + a6*64 + a5*32 + a4*16\
+ a3*8 + a2*4 + a1*2 + a0;
T = 0;
for(n=0;n<10;n++){
SetChanADC(ADC_CH0);
ConvertADC();
while(BusyADC());
TT = (ADRESH*256) + ADRESL;
//TT = (ADRESH<<8)|ADRESL;
T = T + TT;
}
T = T / 10;
T = T / 2;
//T = T - 30; //零調を+30℃の所に設定
//if(T > 256) T = 0;
if(T < setT) PORTBbits.RB2 = 1; //測定温度が設定温度よりも低いならば RB2に出力する
if(T > setT) PORTBbits.RB2 = 0;
lcd_clr();
lcd_locate(0, 0);
lcd_puts(setTemp);
lcd_putsetT(setT);
lcd_locate(1, 0);
lcd_puts(temp);
lcd_putT(T);
Delay_100mS;
}
}